package com.chaosj.webmagic.dto.gushiwen;

import com.chaosj.webmagic.dto.SearchResponseDto;
import com.google.common.base.Splitter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: AuthorResponseDto
 * @description:
 * @author: caoyangjie
 * @date: 2021/8/11
 **/
public class AuthorResponseDto extends SearchResponseDto {

    @Override
    public void addObject(String... args) {
        addAuthor(args[0], args[1], args[2], args[3]);
    }

    /**
     * 添加 作者
     * @param name
     * @param img
     * @param target
     * @param description
     */
    public void addAuthor(String name, String img, String target, String description){
        list.add(new AuthorCareer(name, img, target, description));
    }

    @Data
    @Accessors(chain = true)
    @AllArgsConstructor
    class AuthorCareer {
        private String name;
        private String authorImg;
        private String target;
        private String description;

        @Override
        public String toString(){
            StringBuffer buffer = new StringBuffer();
            buffer.append(String.format("****************************** %s 介绍 start *******************************\n", name));
            buffer.append("* 头像: ").append(authorImg).append("\n");
            buffer.append("* 详情: ").append(target).append("\n\n");
            Splitter.on("。").trimResults().omitEmptyStrings().splitToList(description).forEach(line->{
                buffer.append(line).append("\n");
            });
            buffer.append(String.format("\n****************************** %s 介绍 end *********************************\n", name));
            return buffer.toString();
        }
    }
}
